package org.example.local;


import lombok.AllArgsConstructor;
import org.example.local.event.Event;
import org.example.local.event.WeatherEvent;

import java.util.function.Consumer;


@AllArgsConstructor
//用户
public class User implements EventListener {

    String  name;


    //函数式接口 没有返回值的处理行为
    Consumer<String> consumer;


    //收到天气信息的行为 也就是通知
    public  void receiveInfo(String info)
    {
       consumer.accept(info);
    }


    //拿到事件的行为 要根据不同的事件 做不同的处理
    @Override
    public void onEvent(Event event) {
        if(event instanceof WeatherEvent)
        {
            WeatherEvent weatherEvent = (WeatherEvent) event;
            receiveInfo(weatherEvent.source().toString());
        }

    }
}
